﻿// This code is released under the BSD license.
namespace PugLib.UI
{
    using System;
    using System.Windows.Forms;

    /// <summary>
    /// Utility class used to display a wait cursor
    /// while a long operation takes place and
    /// guarantee that it will be removed on exit.
    /// </summary>
    /// <example>
    /// using(new WaitCursor())
    /// {
    ///     // long running operation goes here...
    /// }
    /// </example>
    public sealed class WaitCursor : IDisposable
    {
        private readonly Cursor _cursor;

        public WaitCursor()
        {
            _cursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
        }

        #region IDisposable Members

        public void Dispose()
        {
            Cursor.Current = _cursor;
            GC.SuppressFinalize(this);
        }

        #endregion
    }
}